package com.dsg.controller;

import com.dsg.entity.Dev;
import com.dsg.entity.Devstatus;
import com.dsg.service.DevService;
import com.dsg.utils.Log;
import com.dsg.vo.DevDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("cus/hkfzjh")
public class DevController {
    private  String msg;
    @Resource
    private DevService devService;
    @GetMapping("/dev")
    public String dev(){
        return "cus/kehufazhan";
    }
    @GetMapping(value = "devlist")
    @ResponseBody
    public List<Dev> list(DevDto devDto){
       List<Dev> list= devService.seachAll(devDto);
       return list;
    }
    @GetMapping(value = "devszlist")
    @ResponseBody
        public List<Devstatus> queryAll(){
            List<Devstatus>list= devService.seachAll();
            return list;
    }
    @GetMapping("/adddev")
    @ResponseBody
    public String add(Dev dev){
        System.out.println(dev);
        try {
            devService.add(dev);
            msg="添加成功~~";
        }catch (Exception ex){
            msg="添加失败···";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
    @GetMapping("/updateDev")
    @ResponseBody
    public String update(Dev dev){
        try{
            devService.update(dev);
            msg="修改成功！";
        }catch (Exception ex){
            msg="修改失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
    @GetMapping("/batchDel")
    @ResponseBody
    public String batchDel(Integer[] ids){
        try {
        devService.batchDel(ids);
            msg="删除成功！";
        }catch (Exception ex){
            msg="删除失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }
}
